/**
 *   Licensed to the Apache Software Foundation (ASF) under one
 *   or more contributor license agreements.  See the NOTICE file
 *   distributed with this work for additional information
 *   regarding copyright ownership.  The ASF licenses this file
 *   to you under the Apache License, Version 2.0 (the
 *   "License"); you may not use this file except in compliance
 *   with the License.  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */
package com.qlangtech.tis.order.center;

import com.google.common.collect.Maps;
import com.qlangtech.tis.assemble.FullbuildPhase;
import com.qlangtech.tis.fs.IFs2Table;
import com.qlangtech.tis.fs.ITableBuildTask;
import com.qlangtech.tis.fs.ITaskContext;
import com.qlangtech.tis.fullbuild.phasestatus.IJoinTaskStatus;
import com.qlangtech.tis.fullbuild.taskflow.DataflowTask;
import com.qlangtech.tis.fullbuild.taskflow.ITemplateContext;
import com.qlangtech.tis.offline.FlatTableBuilder;
import com.qlangtech.tis.sql.parser.ISqlTask;
import java.sql.Connection;
import java.util.Map;

/**
 * @author 百岁（baisui@qlangtech.com）
 * @create: 2020-05-21 11:35
 */
public class MockFlatTableBuilder extends FlatTableBuilder {

    private static final String name = "mock-flat-table-builder";

    @Override
    public void startTask(ITableBuildTask dumpTask) {
        final Connection conn = null;
        ITaskContext context = new ITaskContext() {

            @Override
            public Connection getObj() {
                return conn;
            }
        };
        try {
            dumpTask.process(context);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public DataflowTask createTask(ISqlTask nodeMeta, boolean isFinalNode, ITemplateContext tplContext, ITaskContext taskContext, IJoinTaskStatus joinTaskStatus) {
        return new DataflowTask(nodeMeta.getId()) {

            private Map<String, Boolean> status = Maps.newHashMap();

            @Override
            public void run() throws Exception {
                this.signTaskSuccess();
            }

            @Override
            public FullbuildPhase phase() {
                return FullbuildPhase.JOIN;
            }

            @Override
            public String getIdentityName() {
                return nodeMeta.getExportName();
            }

            @Override
            protected Map<String, Boolean> getTaskWorkStatus() {
                return status;
            }
        };
    }



    @Override
    public String identityValue() {
        return name;
    }

    //    @Override
//    public String getName() {
//        return name;
//    }
}
